/* symtab.h
 *
 * Holds function definitions for the symbol table. The symbol table
 * is implemented as a global hash table that contains local symbol
 * tables for each function
 */

#ifndef SYMTAB_H
#define SYMTAB_H

#include "shared.h"
#include "usrdef.h"
#include <stdlib.h>
#include <string.h>


/* ----------------------------------------------------------------
 * Data type definitions
 * ----------------------------------------------------------------
 */

struct function_description_t {
  struct function_declaration_t *fd;
  /** Basic block label where this function code begins */
  char *basic_block_label;
};


struct symbol_t {
  char *lexeme;
  int id;
  int scope;
  char *class;
  char *func;
  int seen_at_least_once;
  int line_number;
  long offset;
#define SYMTAB_VARIABLE 1
#define SYMTAB_FUNCTION 2
#define SYMTAB_CLASS 3
  int type; /* SYMTAB_VARIABLE - type_denoter
	     * SYMTAB_FUNCTION - function_declaration
	     * SYMTAB_CLASS - class_identification
	     */
  union {
    char *type_name;
    struct function_description_t *fd;
  }data;
  struct symbol_t *next;
};



/* ----------------------------------------------------------------
 * Function declarations
 * ----------------------------------------------------------------
 */

struct function_description_t *symtab_new_function_description();
struct symbol_t* symtab_new();
int symtab_new_scope();
struct symbol_t* symtab_insert(char* lexeme, char *class, int scope, int line_no, char* func);
struct symbol_t* symtab_variable_lookup(char* lexeme, char *class, int scope);
int compare_function_params(struct function_heading_t *a, struct function_heading_t *b);
int compare_function_desig_params(struct function_designator_t *a, struct function_heading_t *b);
int symtab_class_extends(char *this_class, char *base_class);
struct symbol_t* symtab_function_lookup(struct function_heading_t *fh, char *class);
struct symbol_t* symtab_function_desig_lookup(struct function_designator_t *fd, char *class);
void symtab_init();
void symtab_print(int numOfTabs);
void symtab_print_function_declaration(struct function_declaration_t *fd,
				       int numOfTabs);
void symtab_compute_offsets();
int symtab_variable_global(struct symbol_t *s, int scope);
int symtab_get_func_size (char * func);		



#endif
